package com.jie.jie.mvp.ui;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.widget.RelativeLayout;

import com.jaydenxiao.common.base.BaseActivity;
import com.jaydenxiao.common.v.recyclerview.SwipeRecyclerView;
import com.jie.jie.R;
import com.jie.jie.mvp.adpter.MeiRvAdapter1;
import com.jie.jie.mvp.contract.Meicontract;
import com.jie.jie.mvp.model.MeiModel;
import com.jie.jie.mvp.model.MeiziBean;
import com.jie.jie.mvp.persenter.MeiPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;

public class Mei2Activity extends BaseActivity<MeiPresenter, MeiModel> implements Meicontract.View {

    @Bind(R.id.mei2rv)
    SwipeRecyclerView mei2rv;
    @Bind(R.id.activity_mei2)
    RelativeLayout activityMei2;
    private MeiRvAdapter1 adapter1;
    private int page = 1;
    private List<MeiziBean> datas;
    private String url;
    private boolean down;

    @Override
    public int getLayoutId() {
        return R.layout.activity_mei2;
    }

    @Override
    public void initPresenter() {
        mPresenter.setVM(this, mModel);
    }

    @Override
    public void initView() {
        down = true;
        Intent intent = getIntent();
        url = intent.getStringExtra("page");
        url = url + "/";
        mPresenter.getMizi(page,url);
        datas = new ArrayList<>();
        adapter1 = new MeiRvAdapter1(this, datas);
        mei2rv.getRecyclerView().setLayoutManager(new LinearLayoutManager(this));
        mei2rv.setAdapter(adapter1);
//        mei2rv.setRefreshing(false);
        mei2rv.setOnLoadListener(new SwipeRecyclerView.OnLoadListener() {
            @Override
            public void onRefresh() {

            }

            @Override
            public void onLoadMore() {
                page += 1;
                mPresenter.getMEizi(page);
                down = true;
            }
        });
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void returnMeizi(List<MeiziBean> meiziBeen) {

    }

    @Override
    public void returnMizi(List<MeiziBean> meiziBeen) {
        mei2rv.stopLoadingMore();
        datas.addAll(meiziBeen);
        adapter1.notifyDataSetChanged();
        if (page<80) {
            page += 1;
            mPresenter.getMizi(page,url);
        }
    }

    @Override
    public void showLoading(String title) {

    }

    @Override
    public void stopLoading() {

    }

    @Override
    public void showErrorTip(String msg) {

    }

}
